from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone
from clazz.models import Clazz
from task.models import Task


# Create your models here.

class User(AbstractUser):
    # 用于维护 和班级的关系
    clazz = models.ForeignKey(to=Clazz, blank=True, null=True, on_delete=models.CASCADE)

    class Meta(AbstractUser.Meta):
        db_table = "tb_user"
        swappable = "AUTH_USER_MODEL"


class UserTask(models.Model):
    user = models.ForeignKey(to=User,
                             on_delete=models.CASCADE,
                             blank=True,
                             null=True)
    create_time = models.DateTimeField(db_comment='创建时间', default=timezone.now, blank=True, null=True)
    update_time = models.DateTimeField(db_comment='修改时间', blank=True, null=True)
    task = models.ForeignKey(to=Task,
                             on_delete=models.CASCADE,
                             blank=True,
                             null=True)
    task_answer = models.TextField(db_comment="答案",
                                   blank=True,
                                   null=True)
    start_time = models.DateTimeField(db_comment='开始时间', blank=True, null=True)
    task_state = models.IntegerField(db_comment="任务状态", choices=((0, '未开始'), (1, '进行中'), (2, '不会做'),(3,'已提交'),(4, '已检查'), (5, '异常题'),(6,'已完成')))
    submit_time = models.DateTimeField(db_comment='提交时间', blank=True, null=True)
    check_time = models.DateTimeField(db_comment="检查时间", blank=True, null=True)

    class Meta:
        db_table = 'tb_user_task'



